<?php
if (!defined('IN_IA')) {
    exit('Access Denied');
}
if (is_use_weixin()) {
    $openid = get_sysopenid(true);
} else {
    $openid = get_sysopenid(false);
}
$hascoupon = false;
$hascouponcenter = false;
$islogin = false;
if (is_login_account()) {
    $agent = agent_arr();
	$islogin = true;
	$memberinfo = get_member_info($openid);
	$level = array(
        "levelname" => "普通会员"
    );
	
	if($memberinfo['status']==1){
		$level = array(
			"levelname" => "普通分销商"
		);
	}

    if (!empty($memberinfo["level"])) {
        $level = pdo_fetch('select * from ' . tablename('eshop_member_level') . ' where id=:id and uniacid=:uniacid order by level asc', array(
            ':uniacid' => $_W['uniacid'],
            ':id' => $memberinfo['level']
        ));
    }
	
	if (!empty($memberinfo["agentlevel"])) {
		$level = array(
			"levelname" => pdo_fetchcolumn("select levelname from " . tablename("eshop_commission_level") . " where id=".$memberinfo['agentlevel'])
		);
    }
	$agentprice = pdo_fetchcolumn("select sum(price) from " . tablename("eshop_member_success") . " where user_id=".$memberinfo['id']);
	$check_number = true;
	foreach($agent as $k=>$v){
		$name = '';
		$check = pdo_fetch("select price,number from " . tablename("eshop_member_success") . " where user_id=".$memberinfo['id']." and price='".$v[1]."'");
		if($check['price']){
			$name = '<span style="color:blue;">已完成</span>';	
		}else if($memberinfo['agentnum']>=$k){
			$name = '<span style="color:green;">已达标</span>';
		}else{
			$name = '<span style="color:#999;">未达标</span>';
		}
		$agent[$k][2]['status'] = $name;
        if($memberinfo['agentnum']>=$k){
            $number = $k;
        }else if($check_number){
            $number = $memberinfo['agentnum'];
            $check_number = false;
        }else{
            $number = 0;
        }
		$agent[$k][2]['number'] = $number;
	}
}

include page('upgrade');